<template>
  <div class="foods">
    <div class="left" @click="getId">
      <router-link data-id="1" active-class="active" :to="`/index/foods/bottom/1`">锅底</router-link>
      <router-link data-id="2" active-class="active" :to="`/index/foods/bottom/2`">肉类</router-link>
      <router-link data-id="3" active-class="active" :to="`/index/foods/bottom/3`">蔬菜</router-link>
      <router-link data-id="4" active-class="active" :to="`/index/foods/bottom/4`">小吃甜品</router-link>
    </div>
    <div class="center">
      <router-view ></router-view>
      <div class="car" v-show="newlist.length==0?false:true">
        <h1>已选菜品</h1>
        <ul>
          <li v-for="(ele,index) in newlist" :key="index">
            <i class="el-icon-close" @click="del(ele._id)"></i>
            <h2>{{ele.name}}<span class="num">×1</span></h2> 
            <span>{{ele.price.toFixed(2)}}</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name:'Foods',
  data(){
    return {
      num:''
    }
  },
  created() {
    this.$store.dispatch('getList',1)
  },
  computed: {
    ...mapState({
      newlist:(state)=>{
        return state.food.new_list
      }
    })
  },
  methods: {
    getId(e){
        if(e.target.tagName){
          this.num = e.target.dataset.id
          this.$store.dispatch('getList',e.target.dataset.id)
        }
    },
    del(id){
      this.$store.dispatch('delCar',id)
    }
  },
}
</script>

<style scoped lang = "less">
.foods{
  width: 100%;
  .left{
    position: fixed;
    left: 20px;
    z-index: 1;
    a{
      margin-top: 20px;
      display: block;
      width: 70px;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-radius: 45px;
      background-color: #fff;
      box-sizing: border-box;
      box-shadow: 1px 4px 6px #ccc;
      text-decoration: none;
    }
    .active,a:hover{
      border: 1px solid red;
    }
  }
  .center{
  position: relative;
  margin: 0 auto;
  width: 1200px;
  .car{
    position: absolute;
    text-align: center;
    width: 300px;
    border: 1px solid orange;
    right: -250px;
    top: 55px;
    h1{
      color: #888;
      
    }
    ul{
      
      li{
        padding: 0 20px;
        justify-content: space-between;
        height: 30px;
        line-height: 30px;
        display: flex;
        cursor: pointer;
        .num{
          margin-left: 15px;
          color: #dd8615;
        }
        span{
          font-size: 18px;
        }
        i{
          display: none;
          margin-left: -10px;
          font-weight: 700;
          line-height: 30px;
          font-size: 18px;
        }
        i:hover{
          color: red;
        }
      }
      li:hover{

        background-color: orange;
        i{
          display: block;
        }
      }
    }
  }
}
}

</style>